<?php

$peer = ForeignCouponCodePeer::getInstance();
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');
$select = $peer->select();
$select->where(ForeignCouponCodePeer::COUPON_ID, $id)->order('is_active' , 'asc');
$rowset = $peer->fetchAll($select);

$count = $rowset->count();
?>
	<a href="#" class='show_codes'>Показать коды акции</a>
	<div class="coupon_code_bg">
		<div class="coupon_code_block">
			<a href="#" class="close_coupon_code_block">Закрыть [x]</a>
			<?php
				echo "<label><b>Коды акции :: статусы ($count):</b></label>";
				foreach ($rowset as $row) {
					$status = $row->getIsActive() ? 'активен ' : 'закрыт ';
					echo "<a href='#'>{$row['code']} :: {$status} </a> ";
					if ($row->getIsActive()==1)
						echo "<a href='#' class='delete_alike' type='attendant' row_id='{$row->getId()}'>[ x ]</a>";
					echo "<br />";
				}
			?>
		</div>
	</div>
<?php

echo "<br>Загрузить коды из файла <br><input type='file' name='code_list'><br>";
echo "<div class='container_alike'>
<label>Добавить купон по коду <a href='#' class='add_alike' type='alike'>[ + ]</a></label>
";
$request = Zend_Controller_Front::getInstance()->getRequest();
$alikes = $request->getParam('attendant', array());
$first = 1;
foreach ($alikes as $alike) {
	if ($first) {
		$first = 0;
		continue;
	}
	
	if (!$alike) continue;
	echo 
	"<div class='alike_element'>
		<input type='text' autocomplete='off' name='att_ticket[]'  type='attendant' value='$alike' />
		<div class='suggest_result'></div>
	</div>";
}

echo "
	<div class='alike_element'>
		<input type='text' autocomplete='off' name='att_ticket[]'  type='attendant'/>
	</div>
</div>";

?>

<script type='text/javascript'>

var $countOfPhotosAdded = 1;
$(function() {
<?php if (isset($id)) { ?>
	$(".delete_alike").live("click", function() {
		if (!confirm("Вы уверены, что хотите удалить номер купона?")) return false;
		$self = $(this);
		var $url = '/admin/foreign-coupon/delete-code/code_id/' + $self.attr('row_id') + '/coupon_id/' + <?php echo $id; ?>;
		$.ajax({
			url: $url,
			type: 'post',
			dataType: 'json',
			success: function($data) {
				if ($data.result == 'success') {
					$self.prev().remove();
					$self.next().remove();
					$self.remove();
				} else {
					alert($data.message);
				}
			}
		});
		return false;
	});
<?php } ?>

	$(".close_coupon_code_block").live("click", function() {
		$(".coupon_code_bg").css('display' , 'none');
	});

	$(".show_codes").live("click", function() {
		$(".coupon_code_bg").css('display' , 'block');
	});


});

</script>
<style type="text/css">
	.close_coupon_code_block {
		float:right;
	}
	.coupon_code_bg {
		position:fixed;
		z-index:20;
		top:0px;
		left:0px;
		width:100%;
		height:100%;
		background: url("/images/gray_bg.png") repeat transparent scroll;
		display:none;
	}
	.coupon_code_block {
		padding:15px;
		position:fixed;
		left:50%;
		top:70px;
		margin-left:-250px;
		background-color:#D6FFD6;
		width:500px;
		height:450px;
		overflow:scroll;
	}
</style>




